<template>
  <div class="gender-popupbox">
    <van-picker
      title="选择性别"
      show-toolbar
      :default-index="sex"
      :columns="columns"
      @confirm="onConfirm"
      @cancel="onCancel"
    />
  </div>
</template>

<script>
import { updateProfile } from "@/api/axios";
export default {
  name: "gender-popupbox",
  data() {
    return {
      columns: ["男", "女"],
    };
  },
  props: {
    sex: {
      type: [String, Number],
      required: true,
    },
  },
  methods: {
    async onConfirm(value, index) {
      this.$toast.loading({
        message: "修改中...",
        forbidClick: true,
      });
      try {
        const { data: res } = await updateProfile({ gender: index });
        console.log(res,88);
        
        // 完成
        this.$toast.success("修改成功");
        // 1.关闭弹框
        // 2.手动修改用户昵称
        this.$emit("close",index);
        // this.$emit('update')
      } catch (err) {
        console.log(err);
      }
    },
    onCancel() {
      // 取消
      this.$emit("close"); // 关闭弹框
    },
  },
  created() {
      console.log(this.sex);
      
  },
};
</script>

<style lang='less' scoped>
</style>